% TABLE4A.M

clear;
randn('seed',123)

% Table 4a: Monthly WTI price, monthly horizon, 1983-2008
load data4a.txt;
nobs=data4a(:,1); % Number of news announcements
n=length(nobs);   % Number of mining trials left 
vary=data4a(:,2); % Variance of dependent variable (different for each
                  % regression as sample differs)
varx=data4a(:,3); % Variance of the n individual regressors

nrep=100000;                         
for i=1:nrep;

    tstat=zeros(n,1);
    for j=1:n
        y=sqrt(vary(j,1)).*randn(nobs(j,1),1);
        x=sqrt(varx(j,1)).*randn(nobs(j,1),1);
        tstat(j,1)=ols(y,[ones(nobs(j,1),1) x]);
    end;
    
    % Take supremum over n t-statistics for each trial i:
    tmax(i,1)=max(tstat);
    clear y x tstat;
end;

% Compute 5% and 10% one-sided critical values of the distribution of the 
% sup-t-statistic allowing for data mining
%disp([n prctile(tmax,(1-0.05)*100)])
%disp([n prctile(tmax,(1-0.10)*100)])

% P-values
sum(sort(tmax)>0.33)/length(tmax)

